/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ServiceView.java
 *
 * Created on Jun 10, 2011, 9:13:42 PM
 */
package br.ufpe.cin.dsoa.visualvm.gui;

import br.ufpe.cin.dsoa.visualvm.domain.QoSCategory;
import br.ufpe.cin.dsoa.visualvm.domain.QoSCharacteristic;
import br.ufpe.cin.dsoa.visualvm.domain.QosDimension;

import java.util.Date;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;

import javax.swing.JFrame;

import javax.swing.JPopupMenu;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import br.ufpe.cin.dsoa.visualvm.facade.PrincipalFacade;
import com.toedter.calendar.JCalendar;
import java.util.Iterator;
import javax.swing.JOptionPane;

/**
 *
 * @author Administrator
 */
public class BindView extends javax.swing.JPanel {

    private JSpinner activeSpinner;
    private JPopupMenu popUp;
    private JCalendar calendar;
    private PrincipalFacade facade;

    /** Creates new form ServiceView */
    public BindView(PrincipalFacade fac) {
        this.facade = fac;
        initComponents();

        this.calendar = new JCalendar(new Date());
        this.popUp = new JPopupMenu();

        this.popUp.setLightWeightPopupEnabled(true);

        this.popUp.add(this.calendar);
        this.popUp.addPopupMenuListener(new PopupMenuListener() {

            @Override
            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            }

            @Override
            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
                popUpDateChooserClosed();
            }

            @Override
            public void popupMenuCanceled(PopupMenuEvent e) {
            }
        });



    }

    protected void popUpDateChooserClosed() {

        boolean error = false;
        //  if(this.activeSpinner == this.spinnerStart && !this.calendar.getDate().before((Date)this.spinnerStop.getValue()))
        //        error = true;

        //     else if(this.activeSpinner == this.spinnerStop && !this.calendar.getDate().after((Date)this.spinnerStart.getValue()))
        //         error = true;
        // //                
        //    if(!error)
        this.activeSpinner.setValue(this.calendar.getDate());

        //    else
        //        JOptionPane.showMessageDialog(this, "Invalid date choose");


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelTop = new javax.swing.JPanel();
        comboService = new javax.swing.JComboBox();
        comboDimension = new javax.swing.JComboBox();
        comboCharacteristic = new javax.swing.JComboBox();
        comboCategory = new javax.swing.JComboBox();
        comboOperation = new javax.swing.JComboBox();
        separator = new javax.swing.JSeparator();
        panelBottom = new javax.swing.JPanel();
        labelTopic = new javax.swing.JLabel();
        textTopic = new javax.swing.JTextField();
        labelStart = new javax.swing.JLabel();
        panelStartDate = new javax.swing.JPanel();
        spinnerStart = new javax.swing.JSpinner();
        buttonStart = new javax.swing.JButton();
        labelStop = new javax.swing.JLabel();
        panelStopDate = new javax.swing.JPanel();
        spinnerStop = new javax.swing.JSpinner(new SpinnerDateModel());
        buttonStop = new javax.swing.JButton();
        panelListHandlers = new javax.swing.JScrollPane();
        listHandlers = new javax.swing.JList();
        labelHandlers = new javax.swing.JLabel();
        buttonSelectAllHandlers = new javax.swing.JButton();
        buttonSelectNone = new javax.swing.JButton();
        buttonCreate = new javax.swing.JButton();
        comboWindow = new javax.swing.JComboBox();
        textWindowSize = new javax.swing.JTextField();
        labelWindowSize = new javax.swing.JLabel();

        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setMaximumSize(new java.awt.Dimension(111110, 111111));
        setMinimumSize(new java.awt.Dimension(0, 0));
        setPreferredSize(new java.awt.Dimension(422, 300));

        panelTop.setBackground(new java.awt.Color(0, 153, 153));

        comboService.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Select Service..." }));
        comboService.setMinimumSize(new java.awt.Dimension(120, 20));
        comboService.setPreferredSize(new java.awt.Dimension(120, 20));
        comboService.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
                comboServicePopupMenuWillBecomeVisible(evt);
            }
        });
        comboService.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboServiceActionPerformed(evt);
            }
        });

        comboDimension.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Select Dimension..." }));
        comboDimension.setEnabled(false);
        comboDimension.setMinimumSize(new java.awt.Dimension(118, 22));
        comboDimension.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
                comboDimensionPopupMenuWillBecomeVisible(evt);
            }
        });

        comboCharacteristic.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Select Characteristic" }));
        comboCharacteristic.setEnabled(false);
        comboCharacteristic.setMinimumSize(new java.awt.Dimension(118, 22));
        comboCharacteristic.setPreferredSize(new java.awt.Dimension(118, 22));
        comboCharacteristic.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
                comboCharacteristicPopupMenuWillBecomeVisible(evt);
            }
        });
        comboCharacteristic.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboCharacteristicActionPerformed(evt);
            }
        });

        comboCategory.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Select Category..." }));
        comboCategory.setMinimumSize(new java.awt.Dimension(118, 22));
        comboCategory.setPreferredSize(new java.awt.Dimension(118, 22));
        comboCategory.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
                comboCategoryPopupMenuWillBecomeVisible(evt);
            }
        });
        comboCategory.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboCategoryActionPerformed(evt);
            }
        });

        comboOperation.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Select Operation..." }));
        comboOperation.setEnabled(false);
        comboOperation.setMinimumSize(new java.awt.Dimension(118, 22));
        comboOperation.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
                comboOperationPopupMenuWillBecomeVisible(evt);
            }
        });

        javax.swing.GroupLayout panelTopLayout = new javax.swing.GroupLayout(panelTop);
        panelTop.setLayout(panelTopLayout);
        panelTopLayout.setHorizontalGroup(
            panelTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTopLayout.createSequentialGroup()
                .addGroup(panelTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelTopLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(panelTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(comboCategory, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(comboService, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelTopLayout.createSequentialGroup()
                                .addComponent(comboCharacteristic, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comboDimension, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(comboOperation, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(separator, javax.swing.GroupLayout.PREFERRED_SIZE, 421, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(1, Short.MAX_VALUE))
        );
        panelTopLayout.setVerticalGroup(
            panelTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTopLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboService, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboOperation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(separator, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboCategory, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboCharacteristic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboDimension, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelBottom.setBackground(new java.awt.Color(153, 255, 153));
        panelBottom.setMaximumSize(new java.awt.Dimension(130, 20));
        panelBottom.setMinimumSize(new java.awt.Dimension(130, 20));

        labelTopic.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labelTopic.setLabelFor(textTopic);
        labelTopic.setText(org.openide.util.NbBundle.getMessage(BindView.class, "BindView.labelTopic.text")); // NOI18N
        labelTopic.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);

        textTopic.setText(org.openide.util.NbBundle.getMessage(BindView.class, "BindView.textTopic.text")); // NOI18N
        textTopic.setMinimumSize(new java.awt.Dimension(120, 20));
        textTopic.setPreferredSize(new java.awt.Dimension(120, 20));

        labelStart.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labelStart.setLabelFor(spinnerStart);
        labelStart.setText(org.openide.util.NbBundle.getMessage(BindView.class, "BindView.labelStart.text")); // NOI18N
        labelStart.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);

        panelStartDate.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        panelStartDate.setMaximumSize(new java.awt.Dimension(130, 20));
        panelStartDate.setMinimumSize(new java.awt.Dimension(120, 20));
        panelStartDate.setPreferredSize(new java.awt.Dimension(120, 20));
        panelStartDate.setLayout(new java.awt.BorderLayout());

        spinnerStart.setModel(new javax.swing.SpinnerDateModel());
        spinnerStart.setEditor(new javax.swing.JSpinner.DateEditor(spinnerStart, "dd/MM/yy HH:mm"));
        spinnerStart.setMaximumSize(new java.awt.Dimension(32767, 22));
        spinnerStart.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                spinnerStartStateChanged(evt);
            }
        });
        panelStartDate.add(spinnerStart, java.awt.BorderLayout.CENTER);

        buttonStart.setText(org.openide.util.NbBundle.getMessage(BindView.class, "BindView.buttonStart.text")); // NOI18N
        buttonStart.setMaximumSize(new java.awt.Dimension(35, 10));
        buttonStart.setMinimumSize(new java.awt.Dimension(20, 10));
        buttonStart.setPreferredSize(new java.awt.Dimension(20, 10));
        buttonStart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonStartActionPerformed(evt);
            }
        });
        panelStartDate.add(buttonStart, java.awt.BorderLayout.LINE_END);

        labelStop.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labelStop.setLabelFor(spinnerStop);
        labelStop.setText(org.openide.util.NbBundle.getMessage(BindView.class, "BindView.labelStop.text")); // NOI18N
        labelStop.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);

        panelStopDate.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        panelStopDate.setMaximumSize(new java.awt.Dimension(2147483647, 22));
        panelStopDate.setMinimumSize(new java.awt.Dimension(120, 20));
        panelStopDate.setPreferredSize(new java.awt.Dimension(120, 20));
        panelStopDate.setLayout(new java.awt.BorderLayout());

        spinnerStop.setModel(new javax.swing.SpinnerDateModel(new java.util.Date(), null, null, java.util.Calendar.MINUTE));
        spinnerStop.setEditor(new javax.swing.JSpinner.DateEditor(spinnerStop, "dd/MM/yy HH:mm"));
        spinnerStop.setMaximumSize(new java.awt.Dimension(32767, 22));
        spinnerStop.setMinimumSize(new java.awt.Dimension(148, 10));
        spinnerStop.setPreferredSize(new java.awt.Dimension(148, 10));
        spinnerStop.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                spinnerStopStateChanged(evt);
            }
        });
        panelStopDate.add(spinnerStop, java.awt.BorderLayout.CENTER);

        buttonStop.setText(org.openide.util.NbBundle.getMessage(BindView.class, "BindView.buttonStop.text")); // NOI18N
        buttonStop.setMinimumSize(new java.awt.Dimension(20, 9));
        buttonStop.setPreferredSize(new java.awt.Dimension(20, 9));
        buttonStop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonStopActionPerformed(evt);
            }
        });
        panelStopDate.add(buttonStop, java.awt.BorderLayout.LINE_END);

        DefaultListModel model = new DefaultListModel();
        for(String hand : this.facade.getAvailableHandlers())
        model.addElement(hand);
        listHandlers.setModel(model);
        panelListHandlers.setViewportView(listHandlers);

        labelHandlers.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labelHandlers.setText(org.openide.util.NbBundle.getMessage(BindView.class, "BindView.labelHandlers.text")); // NOI18N
        labelHandlers.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);

        buttonSelectAllHandlers.setText(org.openide.util.NbBundle.getMessage(BindView.class, "BindView.buttonSelectAllHandlers.text")); // NOI18N
        buttonSelectAllHandlers.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSelectAllHandlersActionPerformed(evt);
            }
        });

        buttonSelectNone.setText(org.openide.util.NbBundle.getMessage(BindView.class, "BindView.buttonSelectNone.text")); // NOI18N
        buttonSelectNone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSelectNoneActionPerformed(evt);
            }
        });

        buttonCreate.setText(org.openide.util.NbBundle.getMessage(BindView.class, "BindView.buttonCreate.text")); // NOI18N
        buttonCreate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCreateActionPerformed(evt);
            }
        });

        comboWindow.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Select Window Type...", "Time Window", "Package Window" }));
        comboWindow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboWindowActionPerformed(evt);
            }
        });

        textWindowSize.setText(org.openide.util.NbBundle.getMessage(BindView.class, "BindView.textWindowSize.text")); // NOI18N

        labelWindowSize.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labelWindowSize.setLabelFor(textWindowSize);
        labelWindowSize.setText(org.openide.util.NbBundle.getMessage(BindView.class, "BindView.labelWindowSize.text")); // NOI18N

        javax.swing.GroupLayout panelBottomLayout = new javax.swing.GroupLayout(panelBottom);
        panelBottom.setLayout(panelBottomLayout);
        panelBottomLayout.setHorizontalGroup(
            panelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBottomLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelListHandlers, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(panelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(labelHandlers, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(labelTopic, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(textTopic, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelBottomLayout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addGroup(panelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(labelStart, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(panelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(panelStartDate, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(panelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(buttonSelectAllHandlers, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(buttonSelectNone, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(panelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(labelStop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(panelStopDate, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE))
                            .addComponent(textWindowSize, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)
                            .addComponent(labelWindowSize, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)))
                    .addComponent(comboWindow, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(panelBottomLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 176, Short.MAX_VALUE)
                        .addComponent(buttonCreate, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        panelBottomLayout.setVerticalGroup(
            panelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBottomLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelBottomLayout.createSequentialGroup()
                        .addGroup(panelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelBottomLayout.createSequentialGroup()
                                .addComponent(labelStop)
                                .addGap(8, 8, 8)
                                .addComponent(panelStopDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(panelBottomLayout.createSequentialGroup()
                                .addComponent(labelStart)
                                .addGap(8, 8, 8)
                                .addComponent(panelStartDate, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(panelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelBottomLayout.createSequentialGroup()
                                .addComponent(comboWindow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(panelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(panelBottomLayout.createSequentialGroup()
                                        .addGap(20, 20, 20)
                                        .addComponent(textWindowSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(labelWindowSize))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                                .addComponent(buttonCreate))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelBottomLayout.createSequentialGroup()
                                .addComponent(buttonSelectNone)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(buttonSelectAllHandlers)
                                .addGap(23, 23, 23))))
                    .addGroup(panelBottomLayout.createSequentialGroup()
                        .addComponent(labelTopic)
                        .addGap(8, 8, 8)
                        .addComponent(textTopic, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(12, 12, 12)
                        .addComponent(labelHandlers)
                        .addGap(1, 1, 1)
                        .addComponent(panelListHandlers, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(panelTop, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 422, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(panelBottom, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(panelTop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelBottom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

	private void spinnerStartStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerStartStateChanged
	}//GEN-LAST:event_spinnerStartStateChanged

	private void spinnerStopStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerStopStateChanged
            // TODO add your handling code here:
	}//GEN-LAST:event_spinnerStopStateChanged

	private void buttonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartActionPerformed

            this.calendar.setDate((Date) this.spinnerStart.getValue());
            int x = this.panelStartDate.getWidth() - (int) this.popUp.getPreferredSize().getWidth();
            int y = this.panelStartDate.getY() + this.panelStartDate.getHeight();
            this.popUp.show(this.buttonStart, x, y);
            this.activeSpinner = this.spinnerStart;


	}//GEN-LAST:event_buttonStartActionPerformed

	private void buttonStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStopActionPerformed
            this.calendar.setDate((Date) this.spinnerStop.getValue());
            int x = this.panelStopDate.getWidth() - (int) this.popUp.getPreferredSize().getWidth();
            int y = this.panelStopDate.getY() + this.panelStopDate.getHeight();
            this.popUp.show(this.panelStopDate, x, y);
            this.activeSpinner = this.spinnerStop;
	}//GEN-LAST:event_buttonStopActionPerformed

        private void buttonSelectNoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSelectNoneActionPerformed
            this.listHandlers.setSelectedIndices(new int[]{});
            
            //TODO remove this
            QoSCategory perf = new QoSCategory("Performance");
            QoSCharacteristic c1 = new QoSCharacteristic("Response Time", "Operation");
            QoSCharacteristic c2 = new QoSCharacteristic("Throughput", "Operation");
            QosDimension dim1 = new QosDimension("avg", "mills", "decreasing");
            QosDimension dim2 = new QosDimension("max", "units", "increasing");
            
            c1.addDimension(dim1);
            c2.addDimension(dim2);
            
            perf.addCharacteristic(c1);
            perf.addCharacteristic(c2);
            
            this.facade.addQoSCategory(perf);
            
        }//GEN-LAST:event_buttonSelectNoneActionPerformed

        private void buttonSelectAllHandlersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSelectAllHandlersActionPerformed
            this.listHandlers.setSelectionInterval(0, this.listHandlers.getModel().getSize()-1);

        }//GEN-LAST:event_buttonSelectAllHandlersActionPerformed

        private void comboOperationPopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_comboOperationPopupMenuWillBecomeVisible
            //TODO to improve this, we can verify if had any modification on the actual services before load it
            DefaultComboBoxModel model = new DefaultComboBoxModel(this.facade.getAvailableOperationFor(this.comboService.getSelectedItem().toString()));
            model.insertElementAt("Select Operation...", 0);
            this.comboOperation.setModel(model);


        }//GEN-LAST:event_comboOperationPopupMenuWillBecomeVisible

        private void comboCategoryPopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_comboCategoryPopupMenuWillBecomeVisible

            DefaultComboBoxModel model = new DefaultComboBoxModel(this.facade.getAvailableQoSCategories());
            model.insertElementAt("Select Category...", 0);
            this.comboCategory.setModel(model);





        }//GEN-LAST:event_comboCategoryPopupMenuWillBecomeVisible

        private void comboCharacteristicPopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_comboCharacteristicPopupMenuWillBecomeVisible


            Iterator<QoSCharacteristic> it = this.facade.getQoSCategory(this.comboCategory.getSelectedItem().toString()).getCharacteristics().iterator();


            DefaultComboBoxModel model = (DefaultComboBoxModel) this.comboCharacteristic.getModel();
            model.removeAllElements();

            while (it.hasNext()) {
                model.addElement(it.next());
            }

            model.insertElementAt("Select Characteristic...", 0);


        }//GEN-LAST:event_comboCharacteristicPopupMenuWillBecomeVisible

        private void comboDimensionPopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_comboDimensionPopupMenuWillBecomeVisible

            Iterator<QosDimension> it = this.facade.getQoSCategory(this.comboCategory.getSelectedItem().toString()).getQosCharacteristic(this.comboCharacteristic.getSelectedItem().toString()).getDimensions().iterator();
            DefaultComboBoxModel model = (DefaultComboBoxModel) this.comboDimension.getModel();
            model.removeAllElements();
            while (it.hasNext()) {
                model.addElement(it.next());
            }

            model.insertElementAt("Select Dimension...", 0);


        }//GEN-LAST:event_comboDimensionPopupMenuWillBecomeVisible

        private void comboServicePopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_comboServicePopupMenuWillBecomeVisible

            //TODO to improve this, we can verify if had any modification on the actual services before load it

            DefaultComboBoxModel model = new DefaultComboBoxModel(this.facade.getAvailableServices());
            model.insertElementAt("Select Service...", 0);
            this.comboService.setModel(model);


        }//GEN-LAST:event_comboServicePopupMenuWillBecomeVisible

        private void comboCategoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCategoryActionPerformed

            if (this.comboCategory.getSelectedIndex() == 0) {
                this.comboCharacteristic.setEnabled(false);
                this.comboDimension.setEnabled(false);

            } else {
                this.comboCharacteristic.setEnabled(true);
            }


            this.comboCharacteristic.setSelectedIndex(0);
            this.comboDimension.setSelectedIndex(0);

        }//GEN-LAST:event_comboCategoryActionPerformed

        private void comboCharacteristicActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCharacteristicActionPerformed
            if (this.comboCharacteristic.getSelectedIndex() == 0) {
                this.comboDimension.setEnabled(false);

            } else {
                this.comboDimension.setEnabled(true);
            }


            this.comboDimension.setSelectedIndex(0);
        }//GEN-LAST:event_comboCharacteristicActionPerformed

        private void comboServiceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboServiceActionPerformed
            if (this.comboService.getSelectedIndex() == 0) {
                this.comboOperation.setEnabled(false);
            } else {
                this.comboOperation.setEnabled(true);
            }

            this.comboOperation.setSelectedIndex(0);

            // TODO add your handling code here:
        }//GEN-LAST:event_comboServiceActionPerformed

        private void buttonCreateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCreateActionPerformed

            if (this.checkConstraints()) {

                QoSCategory cat = this.facade.getQoSCategory(this.comboCategory.getSelectedItem().toString());

                String[] hand = new String[this.listHandlers.getSelectedValues().length];
                Object[] temp = this.listHandlers.getSelectedValues();

                for (int i = 0; i < hand.length; i++) {
                    hand[i] = temp.toString();
                }
                QoSCharacteristic chara = cat.getQosCharacteristic(this.comboCharacteristic.toString());
                
                String service = this.comboService.getSelectedItem().toString();
                String operation = this.comboOperation.getSelectedItem().toString();
                String category = cat.getID();
                String characteristic = chara.getID();
                
                QosDimension dim = chara.getQoSDimension(this.comboDimension.getSelectedItem().toString());
                String dimStatistic = dim.getStatistic();
                String dimUnit = dim.getUnit();
                
                String windowType = this.comboWindow.getSelectedItem().toString();
                windowType = windowType.substring(0,windowType.indexOf(' ')).toLowerCase().trim();
                int windowSize = Integer.parseInt(this.textWindowSize.toString());
                
                String mills = "mills";
                
                Date startDate = (Date) this.spinnerStart.getValue();
                Date stopDate = (Date) this.spinnerStop.getValue();
                
                
                
                
                System.out.println("Criando Monitoring Configuration:");
                System.out.println("service: " + service);
                System.out.println("operation: "+ operation);
                System.out.println("category: "+category);
                System.out.println("characteristic: "+characteristic);
                System.out.println("statistic: " + dimStatistic);
                System.out.println("unit: "+dimUnit);
                System.out.println("window type: "+windowType);
                System.out.println("window size: "+ windowSize);
                System.out.println("mills: "+ "mills");
                System.out.println("Start date: "+ startDate);
                System.out.println("stop date: "+ stopDate);
                System.out.println("handlers: "+ hand);
                
                System.out.println("");
                
                this.facade.createBind(service, operation, category, characteristic, dimStatistic, dimUnit, windowType, windowSize, mills, startDate, stopDate, hand);
            } else {
                JOptionPane.showMessageDialog(this, "error!!!");
            }


        }//GEN-LAST:event_buttonCreateActionPerformed

        private void comboWindowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboWindowActionPerformed

            //if selected "select window type"
            if(this.comboWindow.getSelectedIndex() == 0)
                this.labelWindowSize.setText("");
            
            //if selected "time window"
            else if(this.comboWindow.getSelectedIndex() == 1)
                this.labelWindowSize.setText("Time (mills)");

            else if(this.comboWindow.getSelectedIndex() == 2)
                this.labelWindowSize.setText("Size (packages)");
            

        }//GEN-LAST:event_comboWindowActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonCreate;
    private javax.swing.JButton buttonSelectAllHandlers;
    private javax.swing.JButton buttonSelectNone;
    private javax.swing.JButton buttonStart;
    private javax.swing.JButton buttonStop;
    private javax.swing.JComboBox comboCategory;
    private javax.swing.JComboBox comboCharacteristic;
    private javax.swing.JComboBox comboDimension;
    private javax.swing.JComboBox comboOperation;
    private javax.swing.JComboBox comboService;
    private javax.swing.JComboBox comboWindow;
    private javax.swing.JLabel labelHandlers;
    private javax.swing.JLabel labelStart;
    private javax.swing.JLabel labelStop;
    private javax.swing.JLabel labelTopic;
    private javax.swing.JLabel labelWindowSize;
    private javax.swing.JList listHandlers;
    private javax.swing.JPanel panelBottom;
    private javax.swing.JScrollPane panelListHandlers;
    private javax.swing.JPanel panelStartDate;
    private javax.swing.JPanel panelStopDate;
    private javax.swing.JPanel panelTop;
    private javax.swing.JSeparator separator;
    private javax.swing.JSpinner spinnerStart;
    private javax.swing.JSpinner spinnerStop;
    private javax.swing.JTextField textTopic;
    private javax.swing.JTextField textWindowSize;
    // End of variables declaration//GEN-END:variables

    public static void main(String[] args) {

        JFrame asd = new JFrame();
        asd.setBounds(500, 500, 500, 500);
        asd.setLayout(null);
        asd.setVisible(true);
        asd.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //BindView s = new BindView(new PrincipalFacade());
        //s.setBounds(0,0,500,500);
        //s.setVisible(true);
        //asd.add(s);
    }

    private boolean checkConstraints() {
        return true;
    }
}
